*CLEANING DATA*

import delimited "ecu_data_July22.csv", clear

gen unemp = 0
replace unemp = 1 if occupation=="Unemployed, looking for work" | occupation=="Unemployed, not looking for work"
replace unemp = . if occupation=="NA"
gen publicemp = 0
replace publicemp = 1 if occupation=="Gov. employee"
replace publicemp = . if occupation=="NA"
gen selfemp = 0
replace selfemp = 1 if occupation=="Self-employed"
replace selfemp = . if occupation=="NA"
gen retired = 0
replace retired = 1 if occupation=="Retired/Disabled"
replace retired = . if occupation=="NA"
gen busowner = 0
replace busowner = 1 if occupation=="Business owner"
replace busowner = . if occupation=="NA"
encode occupation, gen(occu)
gen EDU = real(edu)
drop edu
rename EDU edu
gen edu2 = 0
replace edu2 = 1 if edu>12
encode region, gen(REGION)
drop region
rename REGION region
encode province, gen(prov)
drop province
rename prov province
encode ideologyfac, gen(ideology)
encode pidfac, gen(pid)
gen TRUSTLEG = real(trustleg)
drop trustleg
rename TRUSTLEG trustleg
gen remit = real(remittances)
gen NATPRIDE = real(natpride)
drop natpride
rename NATPRIDE natpride
gen iv = real(eighteenin2000)
drop eighteenin2000
rename iv eighteenin2000
gen AGE = real(age)
drop age
rename AGE age
gen pol_interest = real(polinterest)
drop polinterest
gen dv = real(opiniondollarbi)
drop opiniondollarbi
rename dv opiniondollarbi
gen WELFARE = real(welfare)
drop welfare
rename WELFARE welfare
gen vote_correa = 0
replace vote_correa = 1 if recalledvoteslim=="Voted Correa"
replace vote_correa = . if recalledvoteslim=="NA"
gen otherparty = 0
replace otherpart = 1 if recalledvoteslim=="Voted Other Party"
replace otherparty = . if recalledvoteslim=="NA"

gen mother_edu = .
replace  mother_edu = 0 if motheredu=="None"
replace  mother_edu = 0 if motheredu=="Primary incomplete"
replace  mother_edu = 0 if motheredu=="Primary complete"
replace  mother_edu = 0 if motheredu=="Secondary incomplete"
replace  mother_edu = 1 if motheredu=="Secondary complete"
replace  mother_edu = 1 if motheredu=="University incomplete" | motheredu=="Technical school/Associate degree incomplete"
replace  mother_edu = 1 if motheredu=="University complete" | motheredu=="Technical school/Associate degree complete"

gen reduce_ineq = real(reduceineq)
drop reduceineq
gen pref_stateown = real(prefstateown)
drop prefstateown

gen opinion_dollar = real(opiniondollar)
drop opiniondollar
rename opinion_dollar opiniondollar

gen eighteenin2001 = eighteenin2000
replace eighteenin2001 = 1 if age==33
gen eighteenin2002 = eighteenin2000
replace eighteenin2002 = 1 if age==32 | age==33
gen eighteenin2003 = eighteenin2000
replace eighteenin2003 = 1 if age==31 | age==32 | age==33
gen eighteenin2004 = eighteenin2000
replace eighteenin2004 = 1 if age==30 | age==31 | age==32 | age==33

replace ideology=. if ideology==3

gen center = 0
replace center = 1 if ideology==1
replace center = . if ideology==.
gen right = 0
replace right = 1 if ideology==4
replace right = . if ideology==.
gen left = 0
replace left = 1 if ideology==2
replace left = . if ideology==.

keep opiniondollarbi ideology region wealth01 edu edu2 female trustleg natpride rural eighteenin* ///
	unemp retired remit pol_interest vote_correa otherparty opiniondollar mother_edu pid age ///
	left center right reduce_ineq pref_stateown
		
save "another_day_another_currency.dta", replace

